Skip to content

Commit

Permalink
Accept PathLike in Sphinx.add_message_catalog()
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Oct 25, 2024
1 parent 8cd599c commit 116a430
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions doc/extdev/i18n.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ In practice, you have to:
:caption: src/__init__.py
def setup(app):
package_dir = path.abspath(path.dirname(__file__))
locale_dir = os.path.join(package_dir, 'locales')
package_dir = Path(__file__).parent.resolve()
locale_dir = package_dir / 'locales'
app.add_message_catalog(MESSAGE_CATALOG_NAME, locale_dir)
#. Generate message catalog template ``*.pot`` file, usually in ``locale/``
Expand Down
2 changes: 1 addition & 1 deletion sphinx/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,7 @@ def add_html_math_renderer(
"""
self.registry.add_html_math_renderer(name, inline_renderers, block_renderers)

def add_message_catalog(self, catalog: str, locale_dir: str) -> None:
def add_message_catalog(self, catalog: str, locale_dir: str | os.PathLike[str]) -> None:
"""Register a message catalog.
:param catalog: The name of the catalog
Expand Down
6 changes: 3 additions & 3 deletions sphinx/locale/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import locale
import sys
from gettext import NullTranslations, translation
from os import path
from pathlib import Path
from typing import TYPE_CHECKING

if TYPE_CHECKING:
Expand Down Expand Up @@ -141,11 +141,11 @@ def init(
return translator, has_translation


_LOCALE_DIR = path.abspath(path.dirname(__file__))
_LOCALE_DIR = Path(__file__).parent.resolve()


def init_console(
locale_dir: str | None = None,
locale_dir: str | os.PathLike[str] | None = None,
catalog: str = 'sphinx',
) -> tuple[NullTranslations, bool]:
"""Initialize locale for console.
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


def _init_console(
locale_dir: str | None = sphinx.locale._LOCALE_DIR,
locale_dir: str | os.PathLike[str] | None = sphinx.locale._LOCALE_DIR,
catalog: str = 'sphinx',
) -> tuple[gettext.NullTranslations, bool]:
"""Monkeypatch ``init_console`` to skip its action.
Expand Down

0 comments on commit 116a430

Please sign in to comment.